<?php
	
	include('syscfn.php');
	include('global.php');
	include('conn.php');
	include('pic_conn.php');
	
	$sys_dirs_array = explode('/',get_current_dir_of_the_site());
	$site_dir = $sys_dirs_array[1];
	$server_url = get_server();
	$site_url = 'http://' . $server_url . "/$site_dir";

	//定义系统路径
	$template_name = get_current_template();
	$path = $site_physical_dir . 'sys/';
	define('ROOT_PATH',$site_physical_dir);
	define('SYS_PATH',$path );
	define('SMARTY_DIR',SYS_PATH . 'smarty/libs/');
	define('TEMPLATE_DIR',SYS_PATH . 'smarty/templates/' . $template_name . "/");
	define('CONFIG_DIR',SYS_PATH . 'smarty/configs/');
	define('CACHE_DIR',SYS_PATH . 'smarty/cache/');
	define('COMPILE_DIR',SYS_PATH . 'smarty/templates_c/');
	define('KERNEL_PATH',SYS_PATH . 'kernel/');
	define('DOJO_PATH',SYS_PATH . 'sys/js/dojo/');
	
	//导入SMARTY库
	require(SMARTY_DIR . 'Smarty.Class.php');
	//定义SMARTY路径
	$smarty = new Smarty;
	$smarty->template_dir = TEMPLATE_DIR;
	$smarty->config_dir = CONFIG_DIR;
	$smarty->cache_dir = CACHE_DIR;
	$smarty->compile_dir = COMPILE_DIR;
	//导入系统所需文件
	require KERNEL_PATH   . "class_db.php";
	require KERNEL_PATH   . "class_db_mysql.php";
	require KERNEL_PATH   . "functions.php";
	require KERNEL_PATH   . "class_pic_main.php";
	require KERNEL_PATH   . "class_upload.php";
	require KERNEL_PATH   . "class.smarttemplate.php";
	
	define('SQL_DRIVER','mysql');
	define('SQL_PREFIX',$prefix_tb);
	define('UPLOAD_DIR',ROOT_PATH . 'upload');
	define( 'SESSION_TIMEOUT', $webdb['session_time']."/" );
	
	$DB = new db_driver();
	$DB->obj['sql_database']     = $dbname;
	$DB->obj['sql_user']         = $dbuser;
	$DB->obj['sql_pass']         = $dbpw;
	$DB->obj['sql_host']         = $dbhost;
	$DB->obj['sql_tbl_prefix']	 = $prefix_tb;
	$DB->connect();
	//设置连接字符集
	$DB->cur_query = "
		SET CHARACTER_SET_CLIENT = utf8,
		CHARACTER_SET_CONNECTION = utf8,
		CHARACTER_SET_DATABASE = utf8,
		CHARACTER_SET_RESULTS = utf8,
		CHARACTER_SET_SERVER = utf8,
		COLLATION_CONNECTION = utf8_general_ci,
		COLLATION_DATABASE = utf8_general_ci,
		COLLATION_SERVER = utf8_general_ci,
		AUTOCOMMIT=1";
	$DB->exec_query();
	
	
	//页面初始化处理-----------------------------------
	
	//启动会话
	$session_ok = session_start();
	
	//初始化系统设定(从数据库)
	$DB->build_query( array('select' => '*','from' => 'setting'));
	$DB->exec_query();
	while($row = $DB->fetch_row())
		$sysinfo[$row['varname']]=html_entity_decode(stripslashes($row['value']));
	
	define('SITE_URL',$sysinfo['siteurl']);
	//初始化全局函数库类
	$Elsesky = new Elsesky();
	
	
	
	//初始化系统全局变量
	$web_settings = init_web_settings();
	$db_settings = init_db_settings();
	
	//定义系统全局变量
	//最大搜索时间间隔
	define('MAX_SEARCHING_TIME',20*1);
	//设定系统字符集
	define('SYS_CODE','UTF-8');
	
?>